#include<stdio.h>
int cow[1000];
int sl[300][200];
int ans[1000];
int c[1000];
int min = 1000000;
int n,m;
void dfs(int t, int s);
int pd(int s);
int main()
{
    //freopen("in.txt","r",stdin);
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) scanf("%d",&cow[i]);
    scanf("%d",&m);
    for(int i = 1; i <= m; i++)
    {
        for(int j = 1; j <= n;j++)
        {
            scanf("%d",&sl[i][j]);
        }
    }
    dfs(1,0);
    printf("%d ",min);
    for(int i = 1; i <= min; i++)
    {
        printf("%d ",ans[i]);
    }
}

void dfs(int t, int s)
{
    if(t > m)
    {
        if(pd(s))
        {
            if(s < min)
            {
                min = s;
                for(int i = 1; i <= min; i++)
                {
                    ans[i] = c[i];
                }
            }
        }
        return;
    }
    c[s+1] = t;
    dfs(t+1,s+1);
    c[s+1] = 0;
    dfs(t+1,s);
}

int pd(int s)
{
    for(int i = 1; i <= n; i++)
    {
        int sum = 0;
        for(int j = 1; j <= s; j++)
        {
            sum = sl[c[j]][i] + sum;
        }
        if(sum < cow[i]) return 0;
    }
    return 1;
}